﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using Datalayer;
using Common;
using System.Data;

namespace Portal_KonTum.Admin
{
    public partial class DepartMn : System.Web.UI.Page
    {
        IQueryMgr iq;
        protected void Page_Load(object sender, EventArgs e)
        {
            notes();
            if (!IsPostBack)
            {
                bin();
            }
        }
        void notes()
        {
            if (Request.QueryString["Notes"] != null && Request.QueryString["Active"] != null)
            {
                string snotes = Request.QueryString["Notes"];
                string sactive = Request.QueryString["Active"];
                string sout = MethodCommon.StrQueryNotes(snotes, sactive);
                lbnotes.Visible = true;
                lbnotes.InnerText = sout;
            }
        }
        void bin()
        {
            List<Depart> ex = new List<Depart>();
            iq = QueryMgr.GetDbInstance();
            ex = iq.Dep_GetAllDepart();

            GridView1.DataSource = ex;
            GridView1.DataBind();
        }
        

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //HiddenField hfs = (HiddenField)e.Row.FindControl("hf_cb");
                //Label lb_cs = (Label)e.Row.FindControl("lb_cb");
                //HyperLink lb_cs = (HyperLink)e.Row.FindControl("HyperLink1");
                //iq = QueryMgr.GetDbInstance();
                //if (hfs.Value != null)
                //{
                //    Category st = new Category();
                //    st = iq.Ca_GetCateByID(MethodCommon.Get_Guid(hfs.Value));
                //    lb_cs.Text = st.CategoryName + "";
                //}
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            iq = QueryMgr.GetDbInstance();
            Depart cus = new Depart();
            String index = e.CommandArgument.ToString();

            if (e.CommandName == "rowEdit")
            {
                Response.Redirect("DepartNew.aspx?DepartID=" + index);
            }
            if (e.CommandName == "rowDelete")
            {
                Guid _id = new Guid(index);
                iq = QueryMgr.GetDbInstance();
                iq.Ca_DelOrResCategory(_id);
                bin();
                Response.Redirect("DepartMn.aspx?Notes=StrDel&Active=true");
            }
        }

        protected void GridView1_PageIndexChanged(object sender, EventArgs e)
        {
            bin();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;

            GridView1.EditIndex = -1;
            GridView1.SelectedIndex = -1;
        }
    }
}